package com.jubotech.framework.util;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

import org.springframework.util.Base64Utils;

/**
 * @author xiaoxx
 * @date 2020/1/6 8:45
 */
public class Base64Util {

    /**
     * BASE64解密
     *
     * @param key
     * @return
     */
    public static String decryptBase64(byte[] key){
        try {
            return new String(Base64Utils.decode(key), StandardCharsets.UTF_8.name());
        } catch (UnsupportedEncodingException e) {
        	e.printStackTrace();
        }
        return null;
    }

    /**
     * BASE64加密
     *
     * @param key
     * @return
     */
    public static String encryptBase64(byte[] key){
        return new String(Base64Utils.encode(key));
    }

}
